using System;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.Collections;
using System.Collections.Generic;
using Apache.Cassandra;


namespace Cassandraemon
{


	public static class EnumerableExtensions
	{
	
#region Common
	
		private static CassandraEntity<TOutput> CopyEntityWithoutValue<TInput, TOutput>(CassandraEntity<TInput> source)
		{
			var dist = new CassandraEntity<TOutput>();
			dist.Context = source.Context;
			dist.Key = source.Key;
			dist.ColumnFamily = source.ColumnFamily;
			dist.SuperColumn = source.SuperColumn;
			dist.Column = source.Column;
			
			return dist;
		}
		
#endregion

#region CountColumn
		
		public static int CountColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return 1;
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return 1;
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return 1;
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return 1;
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return list[0].Data.Count();
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return list[0].Data.Count();
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return list[0].Data.Count();
		}
		
		public static int CountColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return 0;
			var list = source.ToList();
			if(list[0].Data == null) return 0;
			return list[0].Data.Count();
		}
		
#endregion

#region CountColumn<TKey>
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 1;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 1;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 1;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 1;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = entity.Data.Count;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = entity.Data.Count;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = entity.Data.Count;
			}
			return dic;
		}
		
		public static Dictionary<TKey, int> CountColumn<TKey>(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			if(source.Count() == 0) return new Dictionary<TKey, int>();
			var dic = new Dictionary<TKey, int>();
			foreach(var entity in source)
			{
				if(entity.Data == null)
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = 0;
				else
					dic[MappingUtil.MappingValueType<TKey>(entity.Key)] = entity.Data.Count;
			}
			return dic;
		}
		
#endregion

#region FirstColumn
		
		public static IEnumerable<CassandraEntity<Column>> FirstColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> FirstColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> FirstColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> FirstColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<Column>> FirstColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<Column>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<Column>, Column>(entity);
				dist.Data = entity.Data.First();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> FirstColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<SuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<SuperColumn>, SuperColumn>(entity);
				dist.Data = entity.Data.First();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> FirstColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterColumn>, CounterColumn>(entity);
				dist.Data = entity.Data.First();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> FirstColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterSuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterSuperColumn>, CounterSuperColumn>(entity);
				dist.Data = entity.Data.First();
				list.Add(dist);
			}
			
			return list;	
		}
		
#endregion

#region FirstOrDefaultColumn
		
		public static IEnumerable<CassandraEntity<Column>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<Column>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<Column>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<Column>, Column>(entity);
				dist.Data = entity.Data.FirstOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<SuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<SuperColumn>, SuperColumn>(entity);
				dist.Data = entity.Data.FirstOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterColumn>, CounterColumn>(entity);
				dist.Data = entity.Data.FirstOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> FirstOrDefaultColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterSuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterSuperColumn>, CounterSuperColumn>(entity);
				dist.Data = entity.Data.FirstOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
#endregion		

#region LastColumn

		public static IEnumerable<CassandraEntity<Column>> LastColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> LastColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> LastColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> LastColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<Column>> LastColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<Column>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<Column>, Column>(entity);
				dist.Data = entity.Data.Last();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> LastColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<SuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<SuperColumn>, SuperColumn>(entity);
				dist.Data = entity.Data.Last();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> LastColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterColumn>, CounterColumn>(entity);
				dist.Data = entity.Data.Last();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> LastColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterSuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterSuperColumn>, CounterSuperColumn>(entity);
				dist.Data = entity.Data.Last();
				list.Add(dist);
			}
			
			return list;	
		}
		
#endregion
		
#region LastOrDefaultColumn
		
		public static IEnumerable<CassandraEntity<Column>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<Column>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<Column>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<Column>, Column>(entity);
				dist.Data = entity.Data.LastOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<SuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<SuperColumn>, SuperColumn>(entity);
				dist.Data = entity.Data.LastOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterColumn>, CounterColumn>(entity);
				dist.Data = entity.Data.LastOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> LastOrDefaultColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			var list = new List<CassandraEntity<CounterSuperColumn>>();
			foreach(var entity in source)
			{
				var dist = CopyEntityWithoutValue<List<CounterSuperColumn>, CounterSuperColumn>(entity);
				dist.Data = entity.Data.LastOrDefault();
				list.Add(dist);
			}
			
			return list;	
		}
		
#endregion
		
#region ReverseColumn
		
		public static IEnumerable<CassandraEntity<Column>> ReverseColumn(this IEnumerable<CassandraEntity<Column>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> ReverseColumn(this IEnumerable<CassandraEntity<SuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> ReverseColumn(this IEnumerable<CassandraEntity<CounterColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> ReverseColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<Column>>> ReverseColumn(this IEnumerable<CassandraEntity<List<Column>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data.Reverse();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<SuperColumn>>> ReverseColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data.Reverse();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<CounterColumn>>> ReverseColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data.Reverse();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<CounterSuperColumn>>> ReverseColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data.Reverse();
			}
			
			return source;	
		}
		
#endregion
		
#region TakeColumn
		
		public static IEnumerable<CassandraEntity<Column>> TakeColumn(this IEnumerable<CassandraEntity<Column>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				if(count < 1)
					entity.Data = null;
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<SuperColumn>> TakeColumn(this IEnumerable<CassandraEntity<SuperColumn>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				if(count < 1)
					entity.Data = null;
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterColumn>> TakeColumn(this IEnumerable<CassandraEntity<CounterColumn>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				if(count < 1)
					entity.Data = null;
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<CounterSuperColumn>> TakeColumn(this IEnumerable<CassandraEntity<CounterSuperColumn>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				if(count < 1)
					entity.Data = null;
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<Column>>> TakeColumn(this IEnumerable<CassandraEntity<List<Column>>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data = entity.Data.Take(count).ToList();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<SuperColumn>>> TakeColumn(this IEnumerable<CassandraEntity<List<SuperColumn>>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data = entity.Data.Take(count).ToList();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<CounterColumn>>> TakeColumn(this IEnumerable<CassandraEntity<List<CounterColumn>>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data = entity.Data.Take(count).ToList();
			}
			
			return source;	
		}
		
		public static IEnumerable<CassandraEntity<List<CounterSuperColumn>>> TakeColumn(this IEnumerable<CassandraEntity<List<CounterSuperColumn>>> source, int count)
		{
			if(source == null) throw new ArgumentNullException("source is null.");
			
			foreach(var entity in source)
			{
				if(entity.Data == null) throw new InvalidOperationException("Column is null.");
			}
			
			foreach(var entity in source)
			{
				entity.Data = entity.Data.Take(count).ToList();
			}
			
			return source;	
		}
		
#endregion
		
	}
}
